var dmNetwork = require("../../utils/network.js");
Page({
  data: {
    ad_list: [],
    fun_list: [],
    banner_list: [],
    weal_list: [],
    is_staff: false,
  },
  goPage(e) {
    try {
      let url = e.currentTarget.dataset.url;
      let type = e.currentTarget.dataset.linktype;
      if (type == 2) {
        if (!this.data.is_staff) {
          wx.showToast({
            title: "只有斗米员工才可参与",
            icon: "none",
            duration: 1500,
          });
        } else {
          let appid = e.currentTarget.dataset.appid;
          wx.navigateToMiniProgram({
            appId: appid,
            path: url,
            extraData: {},
            envVersion: "release",
            success(res) {
              // 打开成功
              that.closeWe();
            },
          });
        }
      } else {
        if (url.startsWith("http")) {
          wx.navigateTo({
            url: "../webview/webview?url=" + url,
          });
        } else {
          wx.navigateTo({
            url: url,
          });
        }
      }
    } catch (error) {
      console.log(error);
    }
  },
  getInfo() {
    let that = this;
    dmNetwork.get(
      dmNetwork.getIndexInfo,
      {
        dmclient: "weixinxcx",
      },
      (res) => {
        if (res.data.errno == 0) {
          let data = res.data.data;
          that.setData({
            ad_list: data.ad_list,
            fun_list: data.fun_list,
            banner_list: data.banner_list,
            weal_list: data.weal_list,
            is_staff: data.is_staff,
          });
        } else {
          wx.showToast({
            title: res.data.errmsg,
            icon: "none",
            duration: 1500,
          });
        }
      },
      (err) => {}
    );
  },
  onLoad: function () {
    this.getInfo();
  },
});
